<?php
class CitiesController extends AppController {

	var $name = 'Cities';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->City->recursive = 0;
		$this->set('cities', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->flash(__('Invalid City', true), array('action'=>'index'));
		}
		$this->set('city', $this->City->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->City->create();
			if ($this->City->save($this->data)) {
				$this->flash(__('City saved.', true), array('action'=>'index'));
			} else {
			}
		}
		if(empty($this->data)){
			$states = $this->City->State->find('list');
			$this->set(compact('states'));
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->flash(__('Invalid City', true), array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->City->save($this->data)) {
				$this->flash(__('The City has been saved.', true), array('action'=>'index'));
			} else {
			}
		}
		if (empty($this->data)) {
			$this->data = $this->City->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->flash(__('Invalid City', true), array('action'=>'index'));
		}
		if ($this->City->del($id)) {
			$this->flash(__('City deleted', true), array('action'=>'index'));
		}
	}

}
?>